#include <2025Linux.h>
int main(int argc, char *argv[])
{
    // ./02_mmap prince.txt
    ARGS_CHECK(argc,2);
    int fd = open(argv[1],O_RDWR);
    ERROR_CHECK(fd,-1,"open");
    struct stat statbuf;
    int ret = fstat(fd,&statbuf);
    ERROR_CHECK(ret,-1,"fstat");
    ret = ftruncate(fd,statbuf.st_size);//用mmap之前 ftruncate一下
    ERROR_CHECK(ret,-1,"ftruncate");
    char *p = (char *)mmap(NULL,statbuf.st_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
    ERROR_CHECK(p,MAP_FAILED,"mmap");
    for(int i = 0; i < statbuf.st_size; ++i){
        if(p[i] >= 'a' && p[i] <= 'z'){
            p[i] -= 32;
        }
        else if(ispunct(p[i])){
            p[i] = ' ';
        }
    }
    munmap(p,statbuf.st_size);
    close(fd);
    return 0;
}

